

package io.renren.modules.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.sys.entity.SysRoleEntity;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 系统用户
 *
 * @author Mark sunlightcs@gmail.com
 */
@Mapper
public interface SysUserDao extends BaseMapper<SysUserEntity> {
	
	/**
	 * 查询用户的所有权限
	 * @param userId  用户ID
	 */
	List<String> queryAllPerms(Long userId);
	
	/**
	 * 查询用户的所有菜单ID
	 */
	List<Long> queryAllMenuId(Long userId);
	
	/**
	 * 根据用户名，查询系统用户
	 */
	SysUserEntity queryByUserName(String username);

	/**
	 * 根据角色查询用户类别
	 * @param role 角色名
	 * @return 用户列表
	 */
	@Select("SELECT t1.user_id, t1.username, t1.email, t1.mobile, t1.status, t1.create_user_id, t1.create_time FROM sys_user t1 " +
			"LEFT JOIN sys_user_role t2 ON t1.user_id = t2.user_id " +
			"JOIN sys_role t3 ON t2.role_id = t3.role_id WHERE t3.role_name = #{role}")
    List<SysUserEntity> queryByRole(@Param("role") String role);

	IPage<SysUserEntity> selectPageByCondition(Page<?> page, @Param("role") String role, @Param("condition") Map<String, Object> condition);
}
